package com.libra.assemble.entity.email;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.libra.assemble.entity.IdEntity;
import com.libra.assemble.xutil.enums.AttachmentType;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;

/**
 * 邮件附件信息.
 * Created by Libra on 15/8/12.
 */
@Entity
@Table(name = "tb_email_attachment")
public class EmailAttachment extends IdEntity {

    /** 邮件内容 */
    private EmailContent emailContent;

    /**
     * ContentType
     */
    private String contentType;

    /**
     * 附件类型
     */
    private AttachmentType attachmentType;

    /**
     * 文件名（下载的附件以日期格式重命名，避免重复）
     */
    private String fileName;

    /**
     * 原始附件名称
     */
    private String originalName;

    /**
     * 访问路径
     */
    private String url;

    /**
     * 邮件的发送日期
     */
    private Date sentDate;

    /**
     * 文件大小
     */
    private Long fileSize;

    @ManyToOne
    @JoinColumn(name="email_content_id")
    public EmailContent getEmailContent() {
        return emailContent;
    }

    public void setEmailContent(EmailContent emailContent) {
        this.emailContent = emailContent;
    }

    public String getContentType() {
        return contentType;
    }

    public void setContentType(String contentType) {
        this.contentType = contentType;
    }

    @Enumerated(EnumType.ORDINAL)
    public AttachmentType getAttachmentType() {
        return attachmentType;
    }

    public void setAttachmentType(AttachmentType attachmentType) {
        this.attachmentType = attachmentType;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getOriginalName() {
        return originalName;
    }

    public void setOriginalName(String originalName) {
        this.originalName = originalName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    /**
     * 'Temporal' 定义时间保存的格式
     * 'DateTimeFormat' 普通输出格式
     * 'JsonFormat' JSON输出的格式
     *
     * @return
     */
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getSentDate() {
        return sentDate;
    }

    public void setSentDate(Date sentDate) {
        this.sentDate = sentDate;
    }

    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }
}
